package com.pengtu.entity.app;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.pengtu.entity.IdEntity;

/**
 * 用户部门
 * 
 * 注释见{@link User}.
 * 
 * @author calvin
 */
@Entity
@Table(name = "R_APP_USERDEPARTMENT")
@JsonAutoDetect(getterVisibility=Visibility.PUBLIC_ONLY)
@JsonIgnoreProperties(ignoreUnknown=true)
public class UserDepartment extends IdEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private User user;							//用户信息
	private Department department;				//部门信息
	private String officalPosition;				//担任职务
	private Date startDate;						//开始日期
	private Date endDate;						//结束日期
	private String remark;						//备注
	
	@ManyToOne(targetEntity=User.class,cascade={CascadeType.ALL})
	@JoinColumn(name="USERID")
	@NotFound(action=NotFoundAction.IGNORE)
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	@ManyToOne(targetEntity=Department.class,cascade=CascadeType.PERSIST)
	@JoinColumn(name="DEPID")
	@NotFound(action=NotFoundAction.IGNORE)
	public Department getDepartment() {
		return department;
	}
	public void setDepartment(Department department) {
		this.department = department;
	}
	
	@Column(name="OFFICALPOSITION")
	public String getOfficalPosition() {
		return officalPosition;
	}
	public void setOfficalPosition(String officalPosition) {
		this.officalPosition = officalPosition;
	}
	@Temporal(TemporalType.DATE)
	@Column(nullable = false,name="STARTDATE")
	public Date getStartDate() {
		return startDate;
	}
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}
	@Temporal(TemporalType.DATE)
	@Column(name="ENDDATE")
	public Date getEndDate() {
		return endDate;
	}
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
}
